Skip to content

Add completion contributor for Bukkit event handlers#2613

Open
Leguan16 wants to merge 3 commits intominecraft-dev:devfrom
Leguan16:feat/bukkit-event-handler-completion-comtributor
Open

Add completion contributor for Bukkit event handlers#2613
Leguan16 wants to merge 3 commits intominecraft-dev:devfrom
Leguan16:feat/bukkit-event-handler-completion-comtributor

Conversation

@Leguan16
Copy link
Copy Markdown

Adds a completion contributor for Bukkit event handlers.

It only works in a class that implements org.bukkit.event.Listener.

It uses templates to generate the method and provide opportunity to change method name and parameter name.

Screen.Recording.2026-04-21.192030.mp4

I initially created this as a poc after someone (Strokkur) posted a video of him doing something similar and wanted to try if i can implement the same logic using the plugin SDK.

If this ends up getting added we can also add Strokkur as co-author for the idea if he wants to, i don't mind that.

@Strokkur424
Copy link
Copy Markdown
Contributor

That's cool

Copy link
Copy Markdown
Member

@Earthcomputer Earthcomputer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to my specific comments:

  • Please make sure to include license headers in all files.
  • The constants (inside the companion objects) should go in BukkitConstants. I believe some of them may already be there.


val eventNameFilter = prefix.substring(2).lowercase()

ClassInheritorsSearch.search(eventBaseClass, scope, true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks expensive. However it's not so easy to cache effectively because the easiest way to do that is using the PSI modification count as the cache key, and since you're in a completion provider that is changing on every keystroke. Leave it as it is for now.

Comment thread src/main/kotlin/platform/bukkit/completion/BukkitEventHandlerInsertHandler.kt Outdated
Comment thread src/main/kotlin/platform/bukkit/completion/BukkitEventHandlerInsertHandler.kt Outdated
template.isToReformat = true

template.addTextSegment("@${EVENT_HANDLER_FQN}\n")
template.addTextSegment("public void ")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the format of this template is hard-coded. Some people might want a different format, like have their methods be package-private (like I do). Some people might also want a different default method name (I've seen people put on as every handler's method name), or even different default event name. Perhaps it could be beneficial to expose properly editing the template in some way? IntelliJ already provides an interface for users to edit templates for these things, so perhaps you could hook into that and provide the method names/event params as built-in variables instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will read into it thanks for making me aware of this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did play around a bit but I don't think i can implement this in a clean way. Especially with using existing logic.

It definitely should be possible but I simply am not familiar enough with kotlin to do it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might play around with this and send a patch if I succeed, no guarantees though.

@Leguan16 Leguan16 force-pushed the feat/bukkit-event-handler-completion-comtributor branch from 3d708a9 to f8e9e4f Compare April 22, 2026 09:35
@Leguan16
Copy link
Copy Markdown
Author

I think i addressed everything in the requested changes. For the editable template I am not familiar enough with Kotlin to add this and currently don't have the time for it. If someone else wants to take a look feel free to do so.

If there is anything else that needs to be changed let me know.

@Leguan16 Leguan16 requested a review from Earthcomputer April 22, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants